/**
 * Copyright (C), 2015-2021, XXX有限公司
 * FileName: ConsultingActivity
 * Author: Gxjkz
 * Date: 2021/7/27 17:56
 * Description: 咨询页面
 * History:
 * <author> <time> <version> <desc>
 * 作者姓名 修改时间 版本号 描述
 */
package com.niuxiaofa.newlaw.Activity;

import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.ColorDrawable;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.example.library.AutoFlowLayout;
import com.example.library.FlowAdapter;
import com.niuxiaofa.newlaw.Base.BaseActivity;
import com.niuxiaofa.newlaw.Bean.ExpertBean;
import com.niuxiaofa.newlaw.Bean.TimeBean;
import com.niuxiaofa.newlaw.R;
import com.niuxiaofa.newlaw.Tools.GlideUtils;
import com.niuxiaofa.newlaw.Tools.RecyclerViewHelp;
import com.niuxiaofa.newlaw.Tools.UIUtils;
import com.niuxiaofa.newlaw.View.CommonPopWindow;
import com.niuxiaofa.newlaw.View.LcardButtonView;
import com.niuxiaofa.newlaw.View.MyLinearlayout;
import com.niuxiaofa.newlaw.adapter.ConsultationTimeAdapter;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * @ClassName: ConsultingActivity
 * @Description: 咨询页面
 * @Author: Gxjkz
 * @Date: 2021/7/27 17:56
 */
public class ConsultingActivity extends BaseActivity implements CommonPopWindow.ViewClickListener {

    @BindView(R.id.flowLayout)
    AutoFlowLayout flowLayout;

    @BindView(R.id.user_img)
    ImageView user_img;

    @BindView(R.id.professional)
    TextView professional;

    @BindView(R.id.personalDescribe)
    TextView personalDescribe;

    @BindView(R.id.personalunit)
    TextView personalunit;

    @BindView(R.id.common_toolbar_title)
    TextView common_toolbar_title;

    @BindView(R.id.lcarview)
    LcardButtonView lcardButtonView;


    @BindView(R.id.my_linear)
    MyLinearlayout my_linear;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_consulting;
    }

    @Override
    protected void initData() {

        ExpertBean.DataDTO.ListDTO expertBean = (ExpertBean.DataDTO.ListDTO) getIntent().getSerializableExtra("ExpertBean");

        if (expertBean != null) {
            GlideUtils.loadChatImage(getContext(), expertBean.getHeader(), user_img);

            addData((ArrayList<String>) expertBean.getTags());


            professional.setText(expertBean.getWorkUnit() + "\n" + "职业" + expertBean.getAddress());

            common_toolbar_title.setText(expertBean.getUserName());

            personalDescribe.setText(expertBean.getPersonalDescribe());

            personalunit.setText(expertBean.getWorkUnit());
        }

        lcardButtonView.setOnClickListener(e -> {

            CommonPopWindow.newBuilder()
                    .setView(R.layout.pop_consulting)
                    .setAnimationStyle(R.style.anim_menu_bottombar)
                    .setBackgroundDrawable(new BitmapDrawable())
                    .setSize(ViewGroup.LayoutParams.MATCH_PARENT, UIUtils.dp2px(getContext(), 350))
                    .setViewOnClickListener(this)
                    .setBackgroundDarkEnable(true)
                    .setBackgroundAlpha(0.7f)
                    .setBackgroundDrawable(new ColorDrawable(999999))
                    .build(this)
                    .showAsBottom(my_linear);


        });


    }

    private void addData(ArrayList<String> list) {
        //流式布局适配器
        flowLayout.setAdapter(new FlowAdapter(list) {
            @Override
            public View getView(int i) {
                //引入视图
                View inflate = LayoutInflater.from(getActivity()).inflate(R.layout.item_textview, null, false);
                //获取视图控件
                TextView auto_tv = inflate.findViewById(R.id.auto_tv);
                //修改值
                auto_tv.setText(list.get(i));
                //清空当前集合

                //返回视图
                return inflate;
            }
        });
    }


    @Override
    public void getChildView(PopupWindow mPopupWindow, View view, int mLayoutResId) {
        List<TimeBean> list = new ArrayList<>();

        for (int i = 0; i < 6; i++) {
            TimeBean timeBean = new TimeBean();
            if (i == 0) {
                timeBean.setTime(1 + "小时");
            }
            timeBean.setTime(i * 3 + "小时");

            list.add(timeBean);
        }


        ConsultationTimeAdapter consultationTimeAdapter = new ConsultationTimeAdapter(list, new ConsultationTimeAdapter.Onclick() {
            @Override
            public void onclick(int c) {


            }
        });
        ;

        RecyclerView recyclerview = view.findViewById(R.id.recyclerview);


        RecyclerViewHelp.setRecyclerGridLayout(recyclerview, 15, 3).setAdapter(consultationTimeAdapter);
        consultationTimeAdapter.notifyDataSetChanged();


    }
}